import asyncio
from lib.net.index import wlan
from lib.websocket import action
from lib.config.index import websocket_config

__service__ = "connect_ws"
__description__ = "connect remote websocket server"

interval = websocket_config.get_interval()


def init():
    # 检查当前网络状态和网络模式
    if not wlan.is_connected():
        print("wifi not connected")

headers = [("Content-Type", "application/json")]

async def run():
    global interval
    while True:
        await action.connect(headers)
        await action.heart_beat()
        # data = await action.read()
        # print(f"ws {interval} recv:", data)
        await asyncio.sleep(interval)
